package gcontent.config.node;

import gcontent.config.error.ConfigEx;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class GlobalNode extends GNode {
	
	private String record_id = null;
	private String record_id_tmp = null;
	
	public String getRecordId()
	{
		return this.record_id;
	}
	
	public String getRecordIdTmp()
	{
		return this.record_id_tmp;
	}

	public GlobalNode(Node node) throws ConfigEx
	{
		NodeList node_list;			

		node_list = node.getChildNodes();
		for(int i = 0; node_list.item(i) != null; i++) {
			Node node_c;
			String name_n;
			
			node_c = node_list.item(i);
			name_n = node_c.getNodeName();

			if(name_n.equals("data-record") || name_n.equals("tmp-record")) {
				NamedNodeMap node_map;
				
				node_map = node_c.getAttributes();
				if(node_map == null || node_map.getNamedItem("ref") == null)
					throw new ConfigEx("not attribute id found it on node " + node_c.getNodeName());
				
				if(name_n.equals("data-record"))
					this.record_id = node_map.getNamedItem("ref").getTextContent();
				else
					this.record_id_tmp = node_map.getNamedItem("ref").getTextContent();
				
			} else if(name_n.charAt(0) != '#')
				throw new ConfigEx("GlobalNode => unknown node " + name_n);
		}
	}

}
